package com.tro.generator.ftl;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.HashMap;
import java.util.Map;

import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;

public class FreeMarkerLoad {
	public static void BuildFreeMarker(Map<String, Object> product,String savePath,String fileName,String freeMarkerName) throws TemplateException, IOException{
		Configuration cfg = new Configuration(Configuration.VERSION_2_3_22);
		// 设置模板目录
		cfg.setClassForTemplateLoading(FreeMarkerLoad.class, "");
		// 设置默认编码格式
		cfg.setDefaultEncoding("UTF-8");
		cfg.setNumberFormat("#");
		// 从设置的目录中获得模板
		Template temp = cfg.getTemplate(freeMarkerName);
		Writer out = new FileWriter(new File(savePath + "/" +fileName));
		temp.process(product, out);
		// 关闭
		out.flush();
		out.close();
	}
}
